package com.example.baserecyclerviewadapterdemo.adapter;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.example.baserecyclerviewadapterdemo.R;
import com.example.baserecyclerviewadapterdemo.entity.QuickMultipleEntity;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public class MultipleItemQuickAdapter extends BaseMultiItemQuickAdapter<QuickMultipleEntity, BaseViewHolder> {
    public MultipleItemQuickAdapter(@Nullable List<QuickMultipleEntity> data) {
        super(data);
        addItemType(QuickMultipleEntity.TEXT, R.layout.item_text_view);
        addItemType(QuickMultipleEntity.IMG,R.layout.item_image_view);
        addItemType(QuickMultipleEntity.IMG_TEXT,R.layout.item_img_text_view);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder holder, QuickMultipleEntity quickMultipleEntity) {
        switch (holder.getItemViewType()) {
            case QuickMultipleEntity.TEXT:
                holder.setText(R.id.tv,quickMultipleEntity.getContent());
                break;
            case QuickMultipleEntity.IMG_TEXT:
                switch (holder.getLayoutPosition() % 2) {
                    case 0:
                        holder.setImageResource(R.id.iv,R.mipmap.animation_img1);
                        break;
                    case 1:
                        holder.setImageResource(R.id.iv,R.mipmap.animation_img2);
                        break;
                }
                break;
            default:
                break;
        }
    }
}
